#ifndef NFILE_H
#define NFILE_H

#include <string>
#include <iostream>
#include <fstream>

namespace Core
{
enum Mode
{
	Mode_Read,
	Mode_Write,
	Mode_Append
};

class NFile
{
	static const int sFileHeader_Size = 1;
public:
	NFile();

	virtual ~NFile(void);

	bool Open(const char* file, Mode mode);

	void Close();

	void Write(const char* value, unsigned int size);

	Mode GetMode() const;

	template<class T>
	T Read();

	FILE* GetFile();

private:
	Mode mFileMode;
	std::ifstream* mFileInputStream;
	std::ostream* mFileOutputStream;
	FILE mFile;
};

template<class T>
T NFile::Read()
{
	char buffer [100];
	if(mFileInputStream != NULL)
	{
		mFileInputStream->read(buffer, 1);
		
		int size = atoi(buffer);

		mFileInputStream->read(buffer, size);

	}
	T value = (T) atoi( buffer );
	return value;
}

template<>
inline bool NFile::Read()
{
	char buffer [100];
	if(mFileInputStream != NULL)
	{
		mFileInputStream->read(buffer, 1);
		
		int size = atoi(buffer);

		mFileInputStream->read(buffer, size);

	}
	int  value = atoi( buffer );
	if(value != 0)
	{
		return true;
	}
	return false;
}
}
#endif //NFILE_H